package schedule

import (
	"errors"
	"strconv"
	"time"
)

const (
	NONE     = "NONE"
	CRON     = "CRON"
	FIX_RATE = "FIX_RATE"
)

// generateNextValidTime 生成有效的下次调度时间
// scheduleType 调度类型
// fromTime 开始时间
// scheduleConf cron 或者 固定频率，单位秒
func generateNextValidTime(scheduleType string, fromTime time.Time, scheduleConf string) (time.Time, error) {
	if scheduleType == FIX_RATE {
		num, err := strconv.Atoi(scheduleConf)
		if err != nil {
			return fromTime, errors.New("scheduleConf 参数错误")
		}
		return fromTime.Add(time.Duration(num) * time.Second), nil
	} else if scheduleType == CRON {
		// TODO 未找到合适 cron 库
		return fromTime, nil
	} else {
		return fromTime, errors.New("无调度类型")
	}
}
